//
// Created by ningjian on 2021/10/15.
//

#include <stdio.h>
#include <stdlib.h>

#include <cmat.h>
#include <detection.h>
#include <musebin.h>

int main(int argc, char *argv[])
{

    char * bin_filename = "../data/layer100_output_file.bin";
//    char * bin_filename = "../data/layer91_output_file.bin";
//    char * bin_filename = "../data/layer82_output_file.bin";

    // read input data
    FILE *fp;
    if ((fp = fopen(bin_filename, "rb")) == NULL)
    {
        puts("Fail to open file!");
        exit(0);
    }
    fseek (fp, 0, SEEK_END);
    size_t file_size = ftell (fp);
    fseek (fp, 0, SEEK_SET);
    uint8_t* input_buff = malloc(file_size);
    fread(input_buff,1,file_size, fp);
    fclose(fp);

    int data_number = 307200;
//    int data_number = 76800;
//    int data_number = 19200;

    CMat *out = DecodeBinData(input_buff,file_size,data_number,16,64*64 );
//    CMat *out = DecodeBinData(input_buff,file_size,data_number,16,32*32 );
//    CMat *out = DecodeBinData(input_buff,file_size,data_number,16,16*16 );
    //CMat_print(out);

    if ((fp = fopen("out_f.txt", "wt")) == NULL)
    {
        puts("Fail to open file!");
        exit(0);
    }
    int i = 0;
    for(i =0; i < data_number ; ++i) {
        fprintf(fp,"%f\n", out->data_ptr[i]);
    }
    fclose(fp);


    return 0;
}